package com.yyc.system.controller;

import com.yyc.core.Result;
import com.yyc.core.ResultGenerator;
import com.yyc.system.model.TGrade;
import com.yyc.system.service.ITGradeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by yyc on 2019/01/04.
 */
@RestController
@RequestMapping("/t/grade")
public class TGradeController {
	@Autowired
	private ITGradeService tGradeService;

	@RequestMapping("/add")
	public Result add(@RequestBody TGrade tGrade) {
		tGradeService.save(tGrade);
		return ResultGenerator.genSuccessResult();
	}

	@RequestMapping("/delete")
	public Result delete(@RequestParam Integer id) {
		tGradeService.deleteById(id);
		return ResultGenerator.genSuccessResult();
	}

	@RequestMapping("/update")
	public Result update(@RequestBody TGrade tGrade) {
		tGradeService.update(tGrade);
		return ResultGenerator.genSuccessResult();
	}

	@RequestMapping("/detail")
	public Result detail(@RequestParam Integer id) {
		TGrade tGrade = tGradeService.findById(id);
		return ResultGenerator.genSuccessResult(tGrade);
	}

	@RequestMapping("/list")
	public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
		PageHelper.startPage(page, size);
		List<TGrade> list = tGradeService.findAll();
		PageInfo<TGrade> pageInfo = new PageInfo<TGrade>(list);
		return ResultGenerator.genSuccessResult(pageInfo);
	}

	// **************************************************************************
	@RequestMapping("/queryClassGrade")
	public Result queryClassGrade(Integer classId) {
		List<TGrade> list = tGradeService.findClassGrade(classId);
		return ResultGenerator.genSuccessResult(list);
	}
}
